package com.example.voting_master.controller;

import com.example.voting_master.common.api.Result;
import com.example.voting_master.entity.VoteTheme;
import com.example.voting_master.service.VoteThemeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/theme")
@CrossOrigin
public class ThemeController {

    @Resource
    private VoteThemeService voteThemeService;

    @GetMapping("/showAll")
    public Result<List<VoteTheme>> showAll() {
        List<VoteTheme> votes = voteThemeService.showAll();

        return Result.success(votes,"返回页面数据成功");
    }

    @GetMapping("/visit")
    public Result<Boolean> visit(Long id) {
        Boolean result = voteThemeService.visitIncrement(id);
        if(result)
            return Result.success(true,"页面访问量增加请求成功");
        else
            return Result.error("页面访问量增加请求失败");
    }
}
